package com.beiding.dbrequest.common;

/**
 * 拦截器
 * 对control的代理模式
 *
 */
public abstract class Intercept implements Control {

    private Control target;

    @Override
    public Object call(Request request) throws Exception {
        if (shouldIntercept(request)) {
            return doIntercept(request);
        }
        return target.call(request);
    }


    /**
     * 是否拦截该请求
     * @param request
     * @return
     */
    public abstract boolean shouldIntercept(Request request);

    /**
     * 执行拦截行为
     * @param request
     * @return 响应结果
     */
    public abstract Object doIntercept(Request request);

    void setTarget(Control target) {
        this.target = target;
    }


}
